package indexingSystem;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.*;

public class WordScanner {
	Pattern filter = IndexingSystem.getFilter();
	Scanner scanner;
	WordScanner(String path) throws IOException {
		int len = path.length();
		String ext = path.substring(len-4);
		if (ext.equals(".txt"))
			scanner = new Scanner(new File(path));
		else if (ext.equals(".pdf"))
			scanner = new Scanner(new PdfScanner(path));
		else{
			throw new IOException("Unknown extension.");
			catch IOException();
		}
		scanner.useDelimiter(filter);
	}
	public boolean hasNext() {
		return scanner.hasNext();
	}
	public String next() {
		return scanner.next();
	}
	public void close() {
		scanner.close();
	}
}
